using System;
using System.Collections.Generic;
using BitBenderGames;
using UnityEngine;
using WorldMap.TouchCamera;
using WorldMapBase;
using WorldMapBase.LOD;

namespace Yoozoo.Modules.InnerCity
{
    public class LodCastle : LodBase
    {
        public bool wallActiveStatus = true;
        public CityScaleItem wallScaleItem;
        
        private List<TileCollideItem> decorateItems = new List<TileCollideItem>(200);
        public bool roadActiveStatus = true;
        
        public TileCollideManager m_tile_collide;

        public float DefaultScaleFactor = 0.1f;
        
        
        private void Awake()
        {
            this.m_tile_collide = base.GetComponent<TileCollideManager>();
        }

        public void UpdateLOD(int lod, float lodPercent)
        {
            if (wallScaleItem)
            {
                wallScaleItem.UpdateLOD(lod,lodPercent);
            }
        }

        public void AddWallScaleItem(CityScaleItem scaleItem)
        {
            wallScaleItem = scaleItem;
            LodBehaviorManager.CastleLodBehavior.SetWallScale(CastleLodBehavior._lastLinearValue);
            wallScaleItem.transform.SetActive(wallActiveStatus);
        }

        public void SetWallScale(float linerValue)
        {
            if (wallScaleItem!=null)
            {
                LodBehaviorManager.CastleLodBehavior.SetWallScale(linerValue);
            }
        }

        public void AddDecorateItem(TileCollideItem dCollideItem)
        {
            dCollideItem.transform.localScale = dCollideItem.defaultScale;//new Vector3(DefaultScaleFactor,DefaultScaleFactor,DefaultScaleFactor);
            decorateItems.Add(dCollideItem);
            if (roadActiveStatus)
            {
                dCollideItem.activeScaleItem.localScale = dCollideItem.defaultScale;
            }
            else
            {
                dCollideItem.activeScaleItem.localScale = dCollideItem.defaultScale;
            }
        }

        public void RemoveDecorateItem(TileCollideItem dCollideItem)
        {
            decorateItems.Remove(dCollideItem);
        }

        public void RemoveAllItem()
        {
            decorateItems.Clear();
        }
        
        public void SetRoadActiveStatus(bool active)
        {
            foreach (var decorate in decorateItems)
            {
                if (active)
                {
                    decorate.activeScaleItem.localScale = decorate.defaultScale;
                }
                else
                {
                    decorate.activeScaleItem.localScale = decorate.defaultScale;
                }
            }

            roadActiveStatus = active;
        }
        
        public override void OnSpawn()
        {
            CastleLodBehavior.AddLodCastle(this);
        }
        
        public override void ResetToPool()
        {
            wallActiveStatus = false;
            decorateItems.Clear();
            CastleLodBehavior.RemoveLodCastle(this);
        }

    }
}